<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
#jquery-table td {
	cursor: pointer !important
}

.load_bg {
	background: #000;
	opacity: 0.1;
	left: 0px;
	top: 0px;
	position: fixed;
	height: 100%;
	width: 100%;
	overflow: hidden;
	z-index: 10000;
}

.load_img {
	left: 50%;
	top: 180px;
	position: fixed;
	height: 50px;
	overflow: hidden;
	z-index: 20000;
}
</style>
</head>
<body class="no-skin">
	<div class="load_bg" style="display: none;"></div>
	<img src="http://img.xmiles.cn/commentloading.gif" class="load_img"
		style="display: none" />
	<div class="page-content">

		<form id="queryForm" action="${cmdList}">
			<div class="page-content-area">
							<div class=" widget-body">
								<!-- <div class="widget-main" style="padding:12px;border:0px solid #ccc; border-top:none;border-bottom:none;"> -->
								<div class="widget-main">
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="sex">时间:</label>
										<div class="col-sm-8">
											<div class="input-daterange input-group">
												<input type="text" data-date-format="yyyy-mm-dd"
													class="fromDate date-picker input-sm form-control"
													style="padding-left: 0px" name="fromDate"> 
											</div>
										</div>
									</div>

									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="functionid">文章id:</label> <input
											type="text" style="padding-left: 0px" name="discoveryid">
									</div>

									<!--  
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="prd_name">用户类型:</label> <select
											class="col-sm-6" name="prd_name" id="prd_name">
											<option value="total">-全部-</option>
											<option value="new">新用户</option>
											<option value="old">老用户</option>
											<option value="new#old">新/老用户</option>
										</select>
									</div>
									-->
								</div>
								<!-- /.widget-main -->
													<div class="col-md-12 center">
						<div class="clearfix form-actions">

							<button class="btn btn-purple  no-border" type="button"
								name="btn-query" onclick="query_any()" id="btn-query">
								<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
								查询
							</button>
						</div>
					</div>
				</div>
							</div>			
			
				<div class="row" id="hidden_pass" style="display: none;">
					<div class="col-xs-12"></div>
					<!-- /.col -->

				</div>
				<!-- /.row -->
				<div class="row">
					<div class="col-xs-12">
						<table id="jquery-table"
							class="table table-striped table-bordered table-hover">
						</table>
					</div>
				</div>
				<!-- /.row -->

			<!-- /.page-content-area -->
		</form>
	</div>
	<!-- /.page-content -->

	<%@ include file="/common/common-js.jsp"%>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<!-- inline scripts related to this page -->
	<script type="text/javascript">
		//【查询】按钮Click事件
		function query_any() {
			$(".load_bg").removeAttr("style");
			$(".load_img").removeAttr("style");

			if (jqTable != null) {
				jqTable.fnDraw();

			} else {
				loaddata();
			}
		}
		var jqTable = null;
		var loaddata = function() {
			jQuery(function($) {

				jqTable = $('#jquery-table')
						.dataTable(
								{
									//数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
									"columnDefs" : [
											{
												"title" : "文章标题", //列名
												"name" : "title",
												"data" : "title", //JSON返回属性
												"targets" : [ 0 ], //第几列
												"class" : "center",
												"width" : "5%", //px 或者 %
												"bSortable" : false,
											},
											{
												"title" : "样式", //列名
												"name" : "stylename",
												"data" : "stylename", //JSON返回属性
												"targets" : [ 1 ], //第几列
												"class" : "center",
												"width" : "10%", //px 或者 %
												"bSortable" : false,
											},
											{
												"title" : "文章分类",
												"name" : "categoryname",
												"data" : "categoryname",
												"targets" : [ 2 ],
												"width" : "4%",
												"class" : "center",
												"bSortable" : false,
											},
											{
												"title" : "发布时间",
												"name" : "pushdate",
												"data" : "pushdate",
												"targets" : [ 3 ],
												"width" : "4%",
												"class" : "center",
												"bSortable" : false,
											},
											{
												"title" : "PV",
												"name" : "PV",
												"data" : "PV",
												"targets" : [ 4 ],
												"width" : "4%",
												"class" : "center",
												"bSortable" : true,
											},
											{
												"title" : "UV",
												"name" : "UV",
												"data" : "UV",
												"targets" : [ 5 ],
												"width" : "4%",
												"class" : "center",
												"bSortable" : true,
											},
											{
												"title" : "ck_module",
												"name" : "ck_module",
												"data" : "ck_module",
												"targets" : [ 6 ],
												"width" : "4%",
												"class" : "center",
												"bSortable" : false,
											},
											{
												"title" : "文章id",
												"name" : "discoveryid",
												"data" : "discoveryid",
												"targets" : [ 7 ],
												"width" : "4%",
												"class" : "center",
												"bSortable" : false,
											}
									],
									"sAjaxSource" : ctx
											+ "/discovery/daily/querydiscoverystat.action?rand="
											+ Math.random(),//数据源URL
									"fnServerData" : function(sSource, aoData,
											fnCallback) {//从服务器请求数据
										var data = $('#queryForm')
												.serializeObject();
										data.aoData = JSON.stringify(aoData);
										$.ajax({
											"dataType" : 'json',
											"type" : "POST",
											"url" : sSource,
											"data" : data,
											"success": function(resp){
												if(resp.status == '0'){//加入判断是否异常
													alert(resp.message);  //异常信息打印处理
												} else {
													$(".load_bg").attr("style","display:none");
													 $(".load_img").attr("style","display:none");
													$("#hidden_pass").attr("style","display:block");
													fnCallback(resp);
													initListPage();
												}
											},
											"error" : function(XMLHttpRequest,
													textStatus, errorThrown) {
												$(".load_bg").attr("style","display:none");
												$(".load_img").attr("style","display:none");
												alert('请求服务器错误,请刷新重试！！');//错误提示，包括服务器重启导致的session失效
						
											}
										});
									},
									"fnRowCallback" : function(nRow, aData,
											iDisplayIndex, iDisplayIndexFull) {
										//bind每一行的双击事件 //
										$(nRow).on('dblclick', '#productWeight', function () {
											$(this).removeAttr("readOnly");
										});
										$(nRow).on('blur', '#productWeight', function () {
											if (!$(this).val().toString().match("^[1-9][0-9]*$")) {
												if(parseInt($(this).val().toString()) == 0) {
													return;
												}
												alert("请填写非0的数字");
												$(this).val(0);
												return;
											}
											$(this).attr("readOnly",true);
										});
									},
									"bPaginate":true,
									"iDisplayLength": 50,
									"bProcessing": true,
									"bScrollInfinite":true,
									"sScrollXInner" : "100%",
									"sScrollY" : "100%",//如果不设置，IE会有问题
									"aaSorting" : [ [ 4, "desc" ] ]
								//初始化加载，默认按第几列排序、排序方式（列从0开始计算）
								});
			});
		}

		//时间控件
		jQuery(function($) {
			$(".date-picker").datepicker({
				autoclose : true,
				todayHighlight: 1
			}).next().on(ace.click_event, function() {
				$(this).prev().focus();
			});
		});

		function doEdit(brandId) {
			window.location = ctx + '/worthbuying/category_detail.action?id=' + brandId + "&type=p";
		}
		
		function doAddpCategory() {
			/* window.open(ctx+"/worthbuying/brand_detail.action?id=-1"); */
			window.location = ctx + '/worthbuying/category_detail.action?id=-1&type=p';
		}
		
		function doDeleteCategory(brandId) {
			/* window.open(ctx+"/worthbuying/brand_detail.action?id=-1"); */
			window.location = ctx + '/worthbuying/pcategory_delete.action?deleteid=' + brandId;
		}

		/* function dodelete(id) {
			if (window.confirm('你确定要删除该记录?')) {
				$.ajax({

					url : ctx + "/groupbuying/customized/delete.action?id="
							+ id,
					"success" : function(resp) {
						query_any();
						alert("删除成功");
					},
					"error" : function() {
						alert("删除失败");
					}
				});
				return true;
			} else {
				return false;
			}
		} */

		function fnFormatDetails(nTr) {
			var aData = $('#jquery-table').fnGetData(nTr);
			alert(aData);
			var sOut = '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">';
			sOut += '<tr><td>Rendering engine:</td><td>' + aData[2] + ' '
					+ aData[5] + '</td></tr>';
			sOut += '<tr><td>Link to source:</td><td>Could provide a link here</td></tr>';
			sOut += '<tr><td>Extra info:</td><td>And any further details here (images etc)</td></tr>';
			sOut += '</table>';

			return sOut;
		}
		
		$(document).ready(function() {
			query_any();
		});
		
		function updateWeight() {
			
			var weight = 0;
			$("#jquery-table tr #productWeight").each(function(index, item) {
				if (weight > 100) {
					return;
				}
				weight += parseInt($(item).val());
				if (weight > 100) {
					alert("权重相加已经超过100，请重新填写");
				}
			});
			if (weight > 100) {
				return;
			} else if(weight <= 0) {
				alert("权重相加为0，请重新填写");
				return;
			}
			
			var data = $('#queryForm').serializeObject();
			var aData = JSON.stringify(data);
			$.ajax({
				url : ctx + "/worthbuying/category_updateWeight.action?data="+aData,
				"success" : function(resp) {
					alert("更新权重成功");
				},
				"error" : function() {
					alert("更新权重失败");
				}
			});
		}
		
		function previewHomePage() {
			var url = "/worthbuying/listPreviewHomePage.action";
			url = encodeURI(url);
			openDialogWithRand(url,1000,1000,"",function (data){});
		}
		
	</script>

</body>
</html>